home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / gtlayout-source.lha / LTP_Clone.c < prev    next >
C/C++ Source or Header  |  1995-09-24  |  8KB  |  317 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8. /*
  9. #undef DB
  10. #define DB(x)    x
  11. */
  12. #ifdef DO_CLONING
  13. VOID __regargs
  14. LTP_CloneScreen(struct LayoutHandle *Handle,LONG Width,LONG Height)
  15. {
  16.     struct ColorSpec    *ColourSpec    = NULL;
  17.     struct ColourRecord    *ColourRecord    = NULL;
  18.     struct CloneExtra    *Extra = Handle -> CloneExtra;
  19.     LONG             AllocationSize;
  20.     UWORD             i,j,*Pens = Handle -> CloneExtra -> ScreenPens,NumColours;
  21.     struct Screen        *Screen;
  22.     ULONG             DisplayID = GetVPModeID(&Handle -> Screen -> ViewPort);
  23.     UWORD             EndPen = (UWORD)~0;
  24.  
  25.     if(Handle -> ExactClone)
  26.         NumColours = Handle -> Screen -> ViewPort . ColorMap -> Count;
  27.     else
  28.     {
  29.         NumColours = Extra -> TotalPens;
  30.  
  31.         DisplayID &= ~(HAM | EXTRA_HALFBRITE);
  32.     }
  33.  
  34.     Height += Handle -> Screen -> BarHeight + 1;
  35.  
  36.     if(Width < Extra -> MinWidth)
  37.         Width = Extra -> MinWidth;
  38.  
  39.     if(Height < Extra -> MinHeight)
  40.         Height = Extra -> MinHeight;
  41.  
  42.     if(Handle -> SimpleClone)
  43.         Pens = &EndPen;
  44.     else
  45.     {
  46.         if(V39)
  47.         {
  48.             if(!(ColourRecord = (struct ColourRecord *)LTP_Alloc(Handle,AllocationSize = sizeof(struct ColourRecord) + sizeof(struct ColourTriplet) * NumColours)))
  49.             {
  50.                 Handle -> Failed = TRUE;
  51.  
  52.                 DB(kprintf("no colours\n"));
  53.  
  54.                 return;
  55.             }
  56.             else
  57.             {
  58.                 ColourRecord -> NumColours = NumColours;
  59.  
  60.                 if(Handle -> ExactClone)
  61.                     GetRGB32(Handle -> Screen -> ViewPort . ColorMap,0,NumColours,(ULONG *)ColourRecord -> Triplets);
  62.                 else
  63.                 {
  64.                     for(i = 0 ; i < NumColours ; i++)
  65.                         GetRGB32(Handle -> Screen -> ViewPort . ColorMap,Extra -> Pens[i],1,(ULONG *)&ColourRecord -> Triplets[i]);
  66.                 }
  67.             }
  68.         }
  69.         else
  70.         {
  71.             if(!(ColourSpec = (struct ColorSpec *)LTP_Alloc(Handle,AllocationSize = sizeof(struct ColorSpec) * (NumColours + 1))))
  72.             {
  73.                 Handle -> Failed = TRUE;
  74.  
  75.                 DB(kprintf("no colours either\n"));
  76.  
  77.                 return;
  78.             }
  79.             else
  80.             {
  81.                 UWORD RGB,Which;
  82.  
  83.                 for(i = 0 ; i < NumColours ; i++)
  84.                 {
  85.                     if(Handle -> ExactClone)
  86.                         Which = i;
  87.                     else
  88.                         Which = Extra -> Pens[i];
  89.  
  90.                     RGB = GetRGB4(Handle -> Screen -> ViewPort . ColorMap,Which);
  91.  
  92.                     ColourSpec[i] . ColorIndex    = i;
  93.                     ColourSpec[i] . Red        = (RGB >> 8) & 0xF;
  94.                     ColourSpec[i] . Green        = (RGB >> 4) & 0xF;
  95.                     ColourSpec[i] . Blue        = (RGB       ) & 0xF;
  96.                 }
  97.  
  98.                 ColourSpec[i] . ColorIndex = -1;
  99.             }
  100.         }
  101.  
  102.         if(Handle -> ExactClone)
  103.         {
  104.             for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
  105.                 Pens[i] = Extra -> Pens[i];
  106.         }
  107.         else
  108.         {
  109.             for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
  110.             {
  111.                 for(j = 0 ; j < NumColours ; j++)
  112.                 {
  113.                     if(Extra -> Pens[j] == Handle -> DrawInfo -> dri_Pens[i])
  114.                     {
  115.                         Pens[i] = j;
  116.  
  117.                         break;
  118.                     }
  119.                 }
  120.             }
  121.         }
  122.  
  123.         Pens[i] = (UWORD)~0;
  124.     }
  125.  
  126.     DB(kprintf("Calling openscreen\n"));
  127.  
  128.     if(Screen = OpenScreenTags(NULL,
  129.         SA_Width,    Width,
  130.         SA_Height,    Height,
  131.         SA_Overscan,    OSCAN_TEXT,
  132.         SA_AutoScroll,    TRUE,
  133.         SA_DisplayID,    DisplayID,
  134.         SA_Behind,    TRUE,
  135.         SA_Depth,    Handle -> SimpleClone ? 2 : Extra -> Depth,
  136.         SA_Colors,    ColourSpec,
  137.         SA_Colors32,    ColourRecord,
  138.         SA_Pens,    Pens,
  139.         SA_Font,    Handle -> TextAttr,
  140.         SA_Title,    Handle -> Screen -> DefaultTitle,
  141.         SA_SharePens,    TRUE,
  142.         SA_Interleaved,    TRUE,
  143.  
  144.         Handle -> SimpleClone ? TAG_IGNORE : SA_BackFill,    &Handle -> BackfillHook,
  145.         Handle -> SimpleClone ? TAG_IGNORE : SA_BlockPen,    Pens[SHADOWPEN],
  146.         Handle -> SimpleClone ? TAG_IGNORE : SA_DetailPen,    Pens[BACKGROUNDPEN],
  147.     TAG_DONE))
  148.     {
  149.         struct DrawInfo *DrawInfo;
  150.  
  151.         DB(kprintf("getting drawinfo\n"));
  152.  
  153.         if(DrawInfo = GetScreenDrawInfo(Screen))
  154.         {
  155.             APTR VisualInfo;
  156.  
  157.             DB(kprintf("getting visualinfo\n"));
  158.  
  159.             if(VisualInfo = GetVisualInfoA(Screen,NULL))
  160.             {
  161.                 UnlockPubScreen(NULL,Handle -> PubScreen);
  162.  
  163.                 FreeScreenDrawInfo(Handle -> Screen,Handle -> DrawInfo);
  164.  
  165.                 FreeVisualInfo(Handle -> VisualInfo);
  166.  
  167.                 Handle -> PubScreen    = NULL;
  168.                 Handle -> Screen    = Screen;
  169.                 Handle -> DrawInfo    = DrawInfo;
  170.                 Handle -> VisualInfo    = VisualInfo;
  171.                 Handle -> TextPen    = Handle -> DrawInfo -> dri_Pens[TEXTPEN];
  172.                 Handle -> BackgroundPen = Handle -> DrawInfo -> dri_Pens[BACKGROUNDPEN];
  173.                 Handle -> ShinePen    = Handle -> DrawInfo -> dri_Pens[SHINEPEN];
  174.                 Handle -> ShadowPen    = Handle -> DrawInfo -> dri_Pens[SHADOWPEN];
  175.                 Handle -> AspectX    = Handle -> DrawInfo -> dri_Resolution . X;
  176.                 Handle -> AspectY    = Handle -> DrawInfo -> dri_Resolution . Y;
  177.  
  178.                 if(Handle -> SimpleClone)
  179.                     Handle -> MaxPen = 0;
  180.                 else
  181.                     Handle -> MaxPen = Extra -> TotalPens - 1;
  182.  
  183.                 Extra -> Screen = Screen;
  184.  
  185.                 LTP_Free(Handle,ColourRecord,AllocationSize);
  186.                 LTP_Free(Handle,ColourSpec,AllocationSize);
  187.  
  188.                 DB(kprintf("fertig\n"));
  189.  
  190.                 return;
  191.             }
  192.  
  193.             FreeScreenDrawInfo(Screen,DrawInfo);
  194.         }
  195.  
  196.         CloseScreen(Screen);
  197.     }
  198.  
  199.     LTP_Free(Handle,ColourRecord,AllocationSize);
  200.     LTP_Free(Handle,ColourSpec,AllocationSize);
  201.  
  202.     Handle -> Failed = TRUE;
  203.  
  204.     DB(kprintf("fehlschlag\n"));
  205. }
  206.  
  207. BOOLEAN __regargs
  208. LTP_PrepareCloning(struct LayoutHandle *Handle)
  209. {
  210.     DB(kprintf("prepare cloning\n"));
  211.  
  212.     if(Handle -> CloneExtra)
  213.         return(TRUE);
  214.     else
  215.     {
  216.         struct DimensionInfo DimensionInfo;
  217.  
  218.         DB(kprintf("getting dimensions\n"));
  219.  
  220.         if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,GetVPModeID(&Handle -> Screen -> ViewPort)))
  221.         {
  222.             DB(kprintf("getting cloneextra\n"));
  223.  
  224.             if(Handle -> CloneExtra = (struct CloneExtra *)LTP_Alloc(Handle,sizeof(struct CloneExtra) + (sizeof(LONG) + sizeof(UWORD)) * Handle -> DrawInfo -> dri_NumPens + sizeof(UWORD)))
  225.             {
  226.                 UWORD     i,j,TotalPens = 0;
  227.                 LONG    *Pens;
  228.                 BOOLEAN  NotFound;
  229.  
  230.                 Handle -> CloneExtra -> Pens        = (LONG *)(Handle -> CloneExtra + 1);
  231.                 Handle -> CloneExtra -> ScreenPens    = (UWORD *)(&Handle -> CloneExtra -> Pens[Handle -> DrawInfo -> dri_NumPens]);
  232.                 Handle -> CloneExtra -> MinWidth    = DimensionInfo . MinRasterWidth;
  233.                 Handle -> CloneExtra -> MinHeight    = DimensionInfo . MinRasterHeight;
  234.                 Handle -> CloneExtra -> MaxWidth    = DimensionInfo . MaxRasterWidth;
  235.                 Handle -> CloneExtra -> MaxHeight    = DimensionInfo . MaxRasterHeight;
  236.  
  237.                 Handle -> CloneExtra -> Bounds . Left    = 0;
  238.                 Handle -> CloneExtra -> Bounds . Top    = 0;
  239.                 Handle -> CloneExtra -> Bounds . Width    = DimensionInfo . MaxRasterWidth;
  240.                 Handle -> CloneExtra -> Bounds . Height = DimensionInfo . MaxRasterHeight;
  241.  
  242.                 Pens = Handle -> CloneExtra -> Pens;
  243.  
  244.                 if(Handle -> ExactClone)
  245.                 {
  246.                     for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
  247.                         Pens[i] = Handle -> DrawInfo -> dri_Pens[i];
  248.  
  249.                     TotalPens = Handle -> DrawInfo -> dri_NumPens;
  250.  
  251.                     Handle -> CloneExtra -> Depth = Handle -> DrawInfo -> dri_Depth;
  252.                 }
  253.                 else
  254.                 {
  255.                     for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
  256.                     {
  257.                         for(j = 0,NotFound = TRUE ; NotFound && j < TotalPens ; j++)
  258.                         {
  259.                             if(Pens[j] == Handle -> DrawInfo -> dri_Pens[i])
  260.                                 NotFound = FALSE;
  261.                         }
  262.  
  263.                         if(NotFound)
  264.                             Pens[TotalPens++] = Handle -> DrawInfo -> dri_Pens[i];
  265.                     }
  266.  
  267.                     for(i = 0 ; i < DimensionInfo . MaxDepth ; i++)
  268.                     {
  269.                         if(TotalPens <= (1L << i))
  270.                         {
  271.                             Handle -> CloneExtra -> Depth = i;
  272.  
  273.                             break;
  274.                         }
  275.                     }
  276.                 }
  277.  
  278.                 DB(kprintf("totalpens=%ld depth=%ld\n",TotalPens,Handle -> CloneExtra -> Depth));
  279.  
  280.                 if((Handle -> CloneExtra -> TotalPens = TotalPens) && Handle -> CloneExtra -> Depth)
  281.                 {
  282.                     DB(kprintf("setting up glyphs\n"));
  283.  
  284.                     if(LTP_GlyphSetup(Handle,Handle -> InitialTextAttr))
  285.                     {
  286.                         Handle -> Failed = Handle -> Rescaled = FALSE;
  287.  
  288.                         LTP_ResetGroups(Handle -> TopGroup);
  289. /*
  290.                         if(!V39 && (Handle -> RPort . TxFlags & FPF_PROPORTIONAL))
  291.                         {
  292.                             LTP_Rescale(Handle,FALSE,FALSE);
  293.  
  294.                             Handle -> Rescaled = FALSE;
  295.                         }
  296. */
  297.                         DB(kprintf("fertig\n\n"));
  298.  
  299.                         return(TRUE);
  300.                     }
  301.                 }
  302.                 else
  303.                 {
  304.                     LTP_Free(Handle,Handle -> CloneExtra,sizeof(struct CloneExtra) + sizeof(LONG) * Handle -> DrawInfo -> dri_NumPens);
  305.  
  306.                     Handle -> CloneExtra = NULL;
  307.                 }
  308.             }
  309.         }
  310.     }
  311.  
  312.     DB(kprintf("fehlschlag\n\n"));
  313.  
  314.     return(FALSE);
  315. }
  316. #endif
  317.